#include "threadbase.h"



static void *thread_routine(void *arg_)
{
    ThreadBase *self = (ThreadBase *)arg_;

    //1) thread start begin
    self->_stoped = false;

    //2)thread run
    //pthread call thread_routine,then call ThreadBase run() function
    self->run(self->_arg);

    //3)thread stop finished
    self->_stoped = true;

    return NULL;
}

void ThreadBase::start(void *arg_, const char *name_)
{
    _started = true;
    _arg = arg_;
    if (name_)
        strncpy (_name, name_, sizeof (_name) - 1);
    int rc = pthread_create (&_descriptor, NULL, thread_routine, this);
    assert (rc == 0);

    rc = pthread_setname_np(_descriptor,_name);
    assert (rc == 0);
}



void ThreadBase::stop()
{
    _started = false;
}

bool ThreadBase::is_stop()
{
    return _stoped;
}

void ThreadBase::run(void *arg_)
{
    printf("ThreadBase::run,line=%d\n",__LINE__);
}
